import { Robot, Group, Resource } from "leafer-game";
import { registerUI } from "@leafer-ui/core";
import { Collider } from "../collider";
const url = '/Outdoor_decoration/Fences.png'

@registerUI()
export class Fences extends Group {
    fences: Robot[] = [];
    collider: Collider<Fences> | undefined;
    public get __tag() { return 'Fences' }
    constructor(){
        super({x: 50, y: 50})
        Resource.loadImage(url).then(() => {
            this.fences = new Array(16).fill('').map((_, index) => {
                return new Robot({
                    tag: 'Fences' + index,
                    robot: { url, size: { width: 16, height: 16 }, total: 16 },
                    actions: {
                        default: [index],
                    },
                    action: 'default', // 设置默认动作
                    // x: (index % 4) * 16,
                    // y: Math.floor(index/4) * 16
                }) 
            })

            this.fences[1].x = 20
            this.fences[1].y = 20
            this.fences[2].x = 20 + 16
            this.fences[2].y = 20
            this.fences[3].x = 20 + 16 + 16
            this.fences[3].y = 20;
            this.collider = new Collider({
                x: this.fences[1].x,
                y: this.fences[1].y,
                width: this.fences[3].width! * 3,
                height: 20,
                colloderInfo: {
                    type: 'static',
                    instance: this
                }
            })
            super.add([this.fences[1], this.fences[2], this.fences[3], this.collider])
        })
    }
}
